package io.gitee.hchaojie.day08.thread.exam;

import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;

public class TestLinkedList {
    public static void main(String[] args) {
        Object lock = new Object();

        Queue<Integer> queue = new LinkedList<>();
        // Queue<Integer> queue = new LinkedBlockingDeque<>();

        for (int i = 0; i < 100; i++) {
            queue.add(i);
        }

        // ExecutorService service = Executors.newCachedThreadPool();
        ExecutorService service = Executors.newFixedThreadPool(100);

        for (int i = 0; i < 10; i++) {
            service.submit(() -> {
                try {
                    Thread.sleep(20);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

//                synchronized (lock) {
                    System.out.println(queue.poll());
//                }
            });
        }
        
        System.out.println("over...");

        // service.shutdown();
    }
}
